package com.bbcloud.util;

import org.joda.time.DateTime;

import java.security.MessageDigest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * Created by liuzhu on 2018/11/22.
 */
public class IDUtil {
    /**
     * 返回ServerId
     * @return
     */
    public static String ServerId() {
        return make16Id();
    }

    /**
     * 返回userId
     * @return
     */
    public static String UserId() {
        return make16Id();
    }

    public static String DayId(){
        return makeDateId();
    }

    public static String ActivityID(){return make16Id();}

    public static String HelpId(){return make16Id();}

    public static String linkID(){return make16Id()+makeDateId();}

    private static String make16Id(){
        //随机生成一位整数
        int random = (int) (Math.random()*9+1);
        String valueOf = String.valueOf(random);
        //生成uuid的hashCode值
        int hashCode = UUID.randomUUID().toString().hashCode();
        //可能为负数
        if(hashCode<0){
            hashCode = -hashCode;
        }
        String value = valueOf + String.format("%015d", hashCode);
        return value;
    }

    private static String makeDateId(){
        Date now=new Date();
        DateTime dateTime = new DateTime(now);
        return dateTime.toString("yyyy-MM-dd");
    }
}
